define(["../common"], function() {
	
	var $form = $("#companyForm");
	var loginDoPath = g_firmDomain + "/company/editDo/json";
	
	loadjs(["validator"], function() {
		$form.validator({
			fields: {
				contacts: 'required;length[2~20]',
				phone: 'required;phone',
				address: 'required;length[3~80]',
				profile: 'length[~2000]'
			},
			valid: valid
		});
	});

	$("[id^='submitBt_']").click(function() {
		$form.trigger('validate');
	});

	function valid(form) {
		if (!$(form).showMsg("正在保存...", 'load', true)) return;
		
		$.post(loginDoPath, $(form).serialize(), function(data){
				if (data.status !== 0) {
					$(form).showMsg(data.message, 'error');
					return;
				} 
				$(form).showMsg("保存成功", 'pass');
		});
	}
});
